\section{Optimization problem}
\label{sec:problem}

Our goal is to simulate the static behaviour of a piece of cloth. We model the piece of cloth as discrete points connected with springs, the discrete points are shown as black dots and the springs are depicted as red lines in figure \ref{fig:springs}. We try to minimize the total potential energy in the system. This potential energy consists of the energy stored in the springs, and the gravitational potential energy. In order to get realistic results, we use different interconnection schemes for the springs. We use structural springs (Figure \ref{fig:structural}), shear springs (Figure \ref{fig:shear}) and bend springs (Figure \ref{fig:bend}). The structural springs ensure that the physical form of the cloth will be retained, the shear springs prevent each rectangle in the structural spring grid from collapsing into a diamond shape which would produce unrealistic results. The bend springs ensure that the cloth will display a realistic curvature instead of sharp angles.

\begin{figure}[H]
\centering
  \subfloat[Structural]{\label{fig:structural}\includegraphics[width=0.3\textwidth]{img/structural.png}}
  \subfloat[Shear]{\label{fig:shear}\includegraphics[width=0.3\textwidth]{img/shear.png}}
  \subfloat[Bend]{\label{fig:bend}\includegraphics[width=0.3\textwidth]{img/bend.png}}
  \caption{Different spring schemes}
  \label{fig:springs}
\end{figure}

\noindent First we need to find a description of the optimisation problem in the following form
\[
	\displaystyle \min_{x \in \mathbb{R}^{n}} \hspace{0.9cm} f(x)
\] \[
	\text{subject to} \hspace{1cm} 
	\begin{matrix}
	g(x) & = & 0 \\
	h(x) & \ge & 0
	\end{matrix}
\] 
\noindent in which $f$ is the objective function $f: \mathbb{R}^{n} \to \mathbb{R}$ which we want to minimize. The equality constraints are given by $g: \mathbb{R}^{n} \to \mathbb{R}^{m}$ and the inequality constraints by $h: \mathbb{R}^{n} \to \mathbb{R}^{q}$. The different elements in the above problem formulation are discussed in the following subsections.

\subsection{Decision variables and constants}
\label{subsec:decisionVariables}
The decision variables $x$ for this optimization problem are the three dimensional coordinates $[x_{ij} \hspace{0.1cm} y_{ij} \hspace{0.1cm} z_{ij}], \hspace{0.1cm} i=1 \ldots N, \hspace{0.1cm} j=1 \ldots N$ of the discrete points of the cloth. The cloth is modelled with N discrete points in the $x$- and $y$-direction. This means that in total there will be $3N^2$ variables to be computed by the solver. 

The problem is parametrized by a few constants. Each discrete point in the cloth has a given mass $m \hspace{0.1cm} [kg]$. This means that every discrete point in the cloth will have potential energy relative to $z = 0$. This energy $E_{h}$ is equal to $mgh$, where $g \hspace{0.1cm} [m/s^2]$ is the acceleration due to gravity ($9.81 m/s^2$).

Other important constants are the spring constant $D \hspace{0.1cm} [N/m]$ and the rest length  $L \hspace{0.1cm} [m]$ of the spring. When the length of the spring differs from it's rest length, elastic potential energy is stored in the spring. This energy $E_{p}$ is equal to $1/2 D \Delta L^2$ where $\Delta L$ is the deviation of the spring from it's rest length.

\subsection{Constraints}

\subsubsection{Equality constraints}

We will use equality constraints to keep the cloth fixed at certain points, e.g. in the
corners. We can also keep a certain edge of the cloth fixed to model a curtain, or a flag. The equality constraints used in the problem are linear and can be formulated as follows 
\begin{equation}
g(x)=A_{eq}x-b_{eq} = 0
\end{equation}

\subsubsection{Inequality constraints}

Inequality constraints will be used to model natural boundaries like a ground constraint,
or a fixed object. This will create a drape-like effect. These constraints can make the
problem non-convex. Linear as well as nonlinear inequality constraints are used.

\subsection{Objective function}

The objective function consists of the sum of all the elastic potential energy contained in the springs and the gravitational potential energy stored in the discrete points. The elastic potential enery in a spring is given by $E_{p} = 1/2D \Delta L^2$ as explained in \ref{subsec:decisionVariables}. The gravitational potential energy is given by $E_{h} = mgh$. The resulting objective function is of the form
\begin{equation}
f(x)=\sum\frac{D}{2}(\sqrt{(x_{ij}-x_{kl})^2+(y_{ij}-y_{kl})^2+(z_{ij}-z_{kl})^2}-L)^2+\sum mgz_{ij}
\end{equation}
where the $ij$ and the $kl$ determine which points are interconnected by springs. The appearance of the square root makes this objective function nonlinear, so the problem is an NLP.
